<?php
// $ cd <project_dir>
// $ hg update

$hg = '/usr/bin/hg';
$_base_dir = dirname(__FILE__);

chdir($_base_dir);
exec (escapeshellcmd("$hg pull"), $lines, $code);
if (!$code) exec (escapeshellcmd("$hg update"), $lines, $code);
if (!$code) {
	$dir = $_base_dir.'/var/cache';
	if (is_dir($dir)) {
		$d = dir($dir);
		while (false !== ($entry = $d->read())) {
			$path = "$dir/$entry";
			if (is_file($path)) unlink($path);
		}
		$d->close();
	}
}

?>
<html>
<body>
	<h1>Updater</h1>
	<h2>code</h2>
	<div><?=htmlspecialchars($code);?></div>
	<h2>output</h2>
	<?php foreach ($lines as $line): ?>
	<div><?=htmlspecialchars($line);?></div>
	<?php endforeach ?>
</body>
</html>


